﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Utils;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Data;

namespace AlertSystem.Business
{
    public partial class Warning_Message
    {
        public static List<Warning_Message> GetAll(int batchSize)
        {
            List<Warning_Message> retList;
            try
            {
                using (SqlConnection conn = AppSetting.GetConnection())
                {
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        using (SqlDataReader rd = SqlHelper.ExecuteReader(trans, CommandType.StoredProcedure, "usp_Warning_Message_GetAll", new SqlParameter("@BatchSize", batchSize)))
                        {
                            retList = ObjectClass.CreateList<Warning_Message>(rd);
                        }
                        trans.Commit();
                    }
                    return retList;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Insert(string warningType, string waringSystem, string message)
        {
            try
            {
                using (DBDataContext context = new DBDataContext(AppSetting.ConnectionString))
                {
                    Warning_Message msg = new Warning_Message();
                    msg.Message_Guid = Guid.NewGuid();
                    msg.WarningType = warningType;
                    msg.WarningSystem = waringSystem;
                    msg.Message = message;
                    msg.Message_Time = DateTime.Now;
                    msg.Status = false;
                    context.Warning_Messages.InsertOnSubmit(msg);
                    context.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
